//
//  ChangeRoleController.m
//  testApp
//
//  Created by iMac on 2018/2/27.
//  Copyright © 2018年 iMac. All rights reserved.
//

#import "ChangeRoleController.h"
#import "TestTabbarController.h"




#define SW [UIScreen mainScreen].bounds.size.width
#define SH [UIScreen mainScreen].bounds.size.height

@interface ChangeRoleController ()

@end

@implementation ChangeRoleController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *changeRoleButton = ({
        UIButton *button = [[UIButton alloc] init];
        button.backgroundColor = [UIColor purpleColor];
        CGFloat a = 100;
        button.frame = CGRectMake((SW - a) / 2.f, (SH - a) / 2.f, a, a);
        [button setTitle:@"切换角色" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(changeRoleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button;
    });
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:changeRoleButton];
}

- (void)changeRoleButtonClick:(UIButton *)sender {
    UIViewController *root = [UIApplication sharedApplication].delegate.window.rootViewController;
    if ([root isKindOfClass:[TestTabbarController class]]) {
        TestTabbarController *tab = (TestTabbarController *)root;
        
        if (tab.role == UserRoleStudent) {
            [tab changeUserRole:UserRoleTeacher];
        }
        else if (tab.role == UserRoleTeacher) {
            [tab changeUserRole:UserRoleStudent];
        }
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
